package cn.luke.basic.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.luke.basic.debounces.Debounce;
import cn.luke.basic.entity.DtoTemplateCourse;
import cn.luke.basic.entity.DtoTemplateRole;
import cn.luke.basic.log_api.LogApi;
import cn.luke.basic.rs.ResponseResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


import cn.luke.basic.utils.MyAssert;


import cn.luke.basic.services.ServiceTemplateRole;

import java.util.List;
import java.util.Map;


/**
 * 模板规则
 * pathName
 */

@RestController
@ResponseResult
@RequestMapping("/templateRole")
public class ControllerTemplateRole implements MyAssert {
    @Resource
    private ServiceTemplateRole serviceTemplateRole;


    /**
     * 模板规则-保存
     */
    @Debounce
    @LogApi("模板规则-保存")
    @PostMapping("/save")
    @SaCheckPermission("templateRole.save")
    public void save(@RequestBody DtoTemplateRole templateRole) {
        intIsNull(templateRole.getTemplateId(), "模板id");
        strIsNull(templateRole.getRoleDescribe(), "规则描述");
        serviceTemplateRole.save(templateRole);
    }

    /**
     * 模板规则-编辑
     */
    @Debounce
    @LogApi("模板规则-编辑")
    @PostMapping("/update")
    public void update(@RequestBody DtoTemplateRole templateRole) {
        intIsNull(templateRole.getId(), "模板ID");
        idIsNull(templateRole.getTemplateId(), "id");
        serviceTemplateRole.updateById(templateRole);
    }


    /**
     * 删除
     */
    @Debounce
    @LogApi("删除")
    @GetMapping("/delete/{id}/{templateId}")
    public void deleteById(@PathVariable("id") Integer id, @PathVariable("templateId") Integer templateId) {
        serviceTemplateRole.deleteById(id, templateId);
    }

    /**
     * 模板规则-状态修改
     */
    @Debounce
    @GetMapping("/updateStatus")
    public void updateStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status, @RequestParam(
            "templateId") Integer templateId) {
        serviceTemplateRole.updateStatus(id, status, templateId);
    }

    /**
     * 模板规则-查询
     */
    @Debounce
    @PostMapping("/list")
    public List<DtoTemplateRole> list(@RequestBody Map<String, Object> params) {
        intIsNull(params.get("templateId"), "模板ID");

        return serviceTemplateRole.findListByParams(params);
    }


}
